#! /bin/make -f
# @file
# @brief Top makefile of board/project
# @author
# + 隐星魂 (Roy.Sun) <https://xwos.tech>
# @copyright
# + (c) 2015 隐星魂 (Roy.Sun) <https://xwos.tech>
# > This Source Code Form is subject to the terms of the Mozilla Public
# > License, v. 2.0 (the "MPL"). If a copy of the MPL was not distributed
# > with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
# >
# > Alternatively, the contents of this file may be used under the
# > terms of the GNU General Public License version 2 (the "GPL"), in
# > which case the provisions of the GPL are applicable instead of the
# > above. If you wish to allow the use of your version of this file
# > only under the terms of the GPL and not to allow others to use your
# > version of this file under the MPL, indicate your decision by
# > deleting the provisions above and replace them with the notice and
# > other provisions required by the GPL. If you do not delete the
# > provisions above, a recipient may use your version of this file
# > under either the MPL or the GPL.
#

WKSPC ?= wkspc
TARGET ?= xwos

all: $(WKSPC) cfg
	$(MAKE) -C $(WKSPC) TARGET=$(TARGET)
	cp ../../$(TARGET).ko $(WKSPC)

$(WKSPC):
	@mkdir -p $@

cfg: $(WKSPC) $(WKSPC)/XuanWuOS.cfg

$(WKSPC)/XuanWuOS.cfg: cfg/XuanWuOS.h cfg/arch.h cfg/cpu.h cfg/soc.h \
 cfg/perpheral.h cfg/board.h cfg/xwos.h cfg/xwmd.h cfg/xwem.h
	@../../xwbs/util/el/mkcfg.el --cfgdir=cfg --topdir=../.. --wkspc=$(WKSPC) -- $(@F)
	@cp ../../xwbs/ko.mk ../../Makefile

c clean d distclean: cfg
	echo "clean ..."
	$(MAKE) -C $(WKSPC) TARGET=$(TARGET) clean
	@rm -rf $(WKSPC)
	@rm -f $(TARGET).ko
	@rm -f ../../Makefile

.DEFAULT:
	@$(MAKE) cfg
	$(MAKE) -C $(WKSPC) TARGET=$(TARGET) $@

.PHONY : all cfg c clean d distclean
